package UILayer;
import java.util.Scanner;

/**
 * This class allows the three elements ProductUI, PersonUI & OrderUI to be connected to a
 * main menu from which all the other menus can be accessed. Users can interact with the IT-system
 * from the main menu and access all functionality the system has integrated.
 * 
 * @author Gruppe 4 
 * @version 4. juni 2012
 */
public class MainMenu
{
    private PersonUI personUI;
    private OrderUI orderUI;
    private ProductUI productUI;

    /**
     * The constructor of the class initializes "PersonUI", "OrderUI" & "ProductUI" which connects the three
     * UI's to the main menu, giving access to all use cases of the system.
     */
    public MainMenu()
    {
        personUI = new PersonUI();
        orderUI = new OrderUI();
        productUI = new ProductUI();
        mainMenuStart();
    }

    /**
     * This method starts the main menu.
     */
   public void mainMenuStart()
   {
        boolean exit = false;
        while (!exit) //! means while exit not is true (that is: false)
        {
            int choice = writeMainMenu();
            switch (choice)
            {
                case 1:
                    orderUI.start();
                    break;  
                case 2:
                    personUI.start();
                    break;
                case 3:
                    productUI.start();
                    break;
                case 4:
                    exit = true;
                    break;
            }
        }
    }
    
    /**
     * This method displays the main menu.
     */
    private int writeMainMenu()
    {       
        // creates a keyboard object to read input
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** Main Menu ***");
        System.out.println(" (1) Order Menu");
        System.out.println(" (2) Person Menu");
        System.out.println(" (3) Product Menu");
        System.out.println(" (4) Close");
        System.out.print("\n Make your choice: ");
        
        int choice = keyboard.nextInt();
        
        return choice;
    }
}